package top.malaoshi.ctrl;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.malaoshi.model.Result;
import top.malaoshi.service.RegSrvImpl;
import top.malaoshi.vo.JsonResult;

import javax.annotation.Resource;

@RestController
//@CrossOrigin(allowCredentials = "true")
public class RegCtrl {

    @Resource
    private RegSrvImpl srvl;

    @RequestMapping("/doReg")
    public JsonResult reg(String phone, String password, String password2){
        JsonResult jsonResult = new JsonResult();
        if(phone==null||"".equals(phone)){
            jsonResult.setCode(1);
            jsonResult.setMsg("手机号不能为空，请输入手机号！");
            return jsonResult;
        }
        if(password==null||"".equals(password)){
            jsonResult.setCode(2);
            jsonResult.setMsg("密码不能为空，请输入密码！");
            return jsonResult;
        }
        if(password2==null||"".equals(password2)){
            jsonResult.setCode(2);
            jsonResult.setMsg("确认密码不能为空，请输入确认密码！");
            return jsonResult;
        }
        if(!password.equals(password2)){
            jsonResult.setCode(3);
            jsonResult.setMsg("密码不一致，请重新输入！");
            return jsonResult;
        }

        Result res=srvl.reg(password,phone);
        jsonResult.setCode(res.getCode());
        jsonResult.setMsg(res.getMsg());
        return jsonResult;
    }
}